Skip to content

Fix arbitrary file write in /validate endpoint (VDP-2966) - #42

Merged
slesaad merged 4 commits into
stagingfrom
fix/validate-path-traversal-vdp2966
Jul 28, 2026
Merged

Fix arbitrary file write in /validate endpoint (VDP-2966)#42
slesaad merged 4 commits into
stagingfrom
fix/validate-path-traversal-vdp2966

Conversation

@slesaad

@slesaad slesaad commented Jul 23, 2026

Copy link
Copy Markdown
Member

Addresses the NASA VDP-2966 finding reported in cloud-management-project#256.

Problem

The unauthenticated POST /validate endpoint passed a client-controlled filename directly into os.path.join(TMP_DIR, filename). Since os.path.join discards the base path when the second argument is absolute — and there were no traversal/separator checks — a caller could steer uploaded content to arbitrary locations in the Lambda's writable area.

Scope note: the Lambda root filesystem is read-only, so this is not a full arbitrary-write-to-code. But /tmp is writable and persists across warm invocations, and the function uses CACHE_DIR=/tmp for pyQuARC's cache. An attacker controlling the full path within /tmp could poison that shared cache (corrupting validation results served to other users) or fill the 512 MB /tmp to DoS the function. CWE-22, CWE-73.

Changes

  • safe_upload_path() — the client filename is never trusted for path construction. Only a sanitized basename is kept (for display), written into a fresh per-request /tmp/uploads/<uuid>/ directory, with a post-resolution containment check. Neutralizes absolute paths, ../ traversal, nested paths, and cross-request filename collisions in warm containers. Also fixes a latent crash when filename is omitted (path.join(TMP_DIR, None)TypeError).
  • try/finally around request handlingwrap_inputs() now runs inside the try, and the per-request AUTH_TOKEN env var is cleared and uploads are removed in finally. Previously an exception in wrap_inputs() (e.g. the missing-filename crash) skipped the AUTH_TOKEN pop, leaking one user's Earthdata token into the next request in a warm container.
  • Stop echoing secrets — the response no longer reflects auth_key or raw file content back in params.
  • Basename in results — return only the uploaded file's basename, never the server path (updated from the old [5:] /tmp/ slice).
  • API throttling — rate 20 / burst 40 on the public stage as defense in depth.

Testing

Verified safe_upload_path() contains every payload from the report (/tmp/evil.txt, ../../etc/passwd, a/b/c.xml, /etc/cron.d/pwn) plus None/empty within /tmp/uploads/<uuid>/; handler.py compiles clean.

The unauthenticated POST /validate endpoint passed a client-controlled
filename directly into os.path.join(TMP_DIR, filename). Because
os.path.join discards the base when the second argument is absolute, and
no traversal/separator checks existed, a caller could write uploaded
content to arbitrary locations in the Lambda's writable area (/tmp),
poisoning the shared pyQuARC cache (CACHE_DIR=/tmp) or filling the disk.

Changes:
- Add safe_upload_path(): keep only a sanitized basename of the client
  filename and write into a fresh per-request /tmp/uploads/<uuid>/
  directory, with a post-resolution containment check. Neutralizes
  absolute paths, ../ traversal, nested paths, and cross-request
  collisions in warm containers. Also fixes a crash when filename is
  omitted (path.join(TMP_DIR, None) -> TypeError).
- Move wrap_inputs() inside try/finally so the per-request AUTH_TOKEN env
  var is always cleared and uploads are always removed, preventing token
  leakage into a subsequent request in a warm container.
- Stop echoing auth_key and raw file content back in the response params.
- Return only the uploaded file's basename in results, never the server
  path.
- Throttle the public API stage (rate 20/burst 40) as defense in depth.

CWE-22, CWE-73.
@slesaad
slesaad changed the base branch from master to staging July 23, 2026 19:57
@slesaad
slesaad requested a review from xhagrg July 23, 2026 19:57
slesaad added 3 commits July 23, 2026 15:00
The runners dropped Python 3.8, so the lint workflow failed with
"Version 3.8 with arch x64 not found", and the older action majors run
on the now-deprecated Node 20.

- lint.yml: setup-python@v1 (3.8) -> @v6 (3.9), matching the Lambda
  runtime and the deploy workflows; checkout@v2 -> @v5;
  wearerequired/lint-action@v1 -> @v2.
- deploy.yml / update_pyquarc.yml: checkout@v2 -> @v5,
  configure-aws-credentials@v1 -> @v4, setup-python@v2 -> @v6.
- deploy.yml: setup-node@v2 -> @v5 and bump the CDK build Node from the
  EOL 14.15.1 to 20 LTS.
The lint workflow flagged pre-existing issues in the deploy package:

- flake8 F401: remove unused DockerImage import in stack.py.
- black: reformat the BundlingOptions command list onto separate lines
  and drop the extra blank line in app.py.

All 8 tracked Python files now pass `black --check --line-length 100`
and `flake8`.
…ation

Update GitHub Actions to Node 24 majors and Python 3.9
@slesaad
slesaad merged commit 638f6a9 into staging Jul 28, 2026
3 checks passed
@slesaad slesaad mentioned this pull request Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants